package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.Autofill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);


    //新增套餐
    @Autofill(OperationType.INSERT)
    void saveSetmael(Setmeal setmeal);

    //新增套餐对应菜品
    @Insert("insert into setmeal_dish(setmeal_id,dish_id,name,price,copies) values(#{setmealId},#{dishId},#{name},#{price},#{copies})")
    void saveSetmealDish(SetmealDish setmealDish);

    //套餐分页查询
    Page<SetmealVO> getSetealPage(SetmealPageQueryDTO setmealPageQueryDTO);

    //获取当前id对应套餐
    @Select("select * from setmeal where id=#{SetmealId}")
    Setmeal getById(Long SetmealId);

    void deleteByIds(List<Long> ids);

    void deleteBySetmealIds(List<Long> ids);

    //在套餐餐品表中查询套餐id对应菜品
    @Select("select * from setmeal_dish where setmeal_id=#{id}")
    List<SetmealDish> getBySetmealId(Long id);

    @Autofill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    //删除当前套餐id相关的菜品信息
    @Delete("delete from setmeal_dish where setmeal_id=#{id}")
    void deleteBySetmealId(Long id);

}
